Split messy code to views.api module