writing output correctly