moved code around added comments