type hints added, unnessarry casts removed