Add type checking/casting to open middle level function

Close #65