Changed the structure again and abstracted routine creation.