bunch of bug fixes and cleaning up unecessary code.

CND currently not working.