Refactor & logic improvements.