layout refactored with working layout functions