Removed heredoc syntax for better maintenance. Separate functions.php now for calculations and MYSQL queries.