Added testing framework + refactored a little