Moved a little code around to prepare for modularizing of code