Moved authentication code to own module