Basics registration works

Also fixed some small bugs. Also optimalized some code.