Some refactoring and further implementation of auth check