moved code around to make more sense