moved code around to their correct places