now working code with testing and stuff