Refactor of work script, don't think it works