Update function syntax
Move type check after set in use to fix function type bug