moved some code around