Updated logic and test