moved some code and comments