Updated logic, created tests
--