Lots of cleanup and porting

Ported some of the functions, but it seems like that the type checking
system does not work