this could be organized nicer, it is impossible to read as-is.