added more functionality and some cleanup