Split up code to make things more manageable
Work in progress
Work in progress