Separation into functions/other minor refactors