Cleaned up the code. Created createLayout function.