Fixed a few minor bugs & added tests