updated for cleaner logic