bug fixes + more type checking