fine tuning functions and cleaning up

cleaning up and fixing up some problems