Added flush and with command and cleaned up a bit