cleaned up code, fixed bugs & rm unused file