Radical refac!

Solved the cast problem by generics
Javadoc for generics