Bug fixes and updated and added more unit tests