Add type, fix many bugs and shit