more bug fixes + code cleanup
lots of little bugs fixed