Fixed type mismatch issues. Bit hacky, but it will do.