Add proper tests and remove debug code