refactored bug with redirection out