Refactored route handlers
Added explaining comments.