Added testing and fixed bugs