Fixed issues and added tests