Started organizing the stuff into separate functions