Moved functions from main script to new module 'core'