Made a few changes and added a few test functions