cleaned up logic