rewritten again with better logic/catches