clean extern implementation and other minor fixes