Moved all the logic in a single file.