simplify code

simplified the structure and removed templates