moved code around under comments, added functionality