moving code around to make cleaner