Added tests and reviewed code also fixes #109