fix #248 and other issues with inheritance/scoping