replaced the logged in if statement with a function