cleaned up control flow