Added tests and made minor tweaks