fixes to make this work as an external module