tried to do cast, fixed some instanceof stuff