LOTS of changes to make it work as a true pails module