finished basic logic