Improved readability and added tests