moved some code out