Cleaned up code and added login redirect