fix registration, clean up code