cleaning up some code and making it much simpler