added validation, refactored sources, added minor features, polishing the code

Just merge it please, further discussion will of course follow.