warning: things start to get hard here