Structuring code and first stage of sql file