Reorganize code and only export registration function