Added perl hooks, minor cleanup