cleaned things up and rewrote some code