First complete version, kinda works