Removed debug messages, removed code duplication