#14438 Removed redundant sql queries, cleaned view from query logic