Change to anonymous functions
Move navigation logic to a common function