refactored authentication check and moved it to its own module.