Moved methods with logic to the end, added flush method.