fixed up and clearned up code