generic type parameters and some bug fixes