move reverse logic to seperate function