Refactored script into proper module.