Move actual functionality into separate class so that it can be reused from script hooks