Added main loop processing and SQL commands