fixes #627 #791 This also fixes an issue where the class tables do not extend the correct class when dealing with inheritance. Also new tests to cover this functionality.