Added tests and made improvements