Fix style errors and add output buffering