moved some code around to keep working dir clean