Moved navigation to a function with some basic functionality.
Added empty check.