Refactoring layout and removing dead code