Fixed numerous bugs and added more functionality