fixed #154 checks with instanceof the types before casting to them