better logic structure