Fix command for setting layout and refactor a bit