Ported and refined code from previous project. Finished layouts.