Minor code fixes and added tests