Moved various functions from the service control script into a lib folder for better code reuse.