better logic flow