Minor refactorying, implementing better type-safety with Generics.