Code cleanup and added a new test