Moved buffer-parsing from main_loop to its own function. Replaced string.find() with keyword "in" at points where it made more sense to use "in"