refactored register method