add layout unit tests, refactor