closure type-checking + fix type annotaions and bugs