Debugged and added tests. Beware immuatble classes