Move user check to middleware
Replaced ifs with ternary