moved some code around
cleaned