adds AMD and CommonJS export support

Just made it more module friendly and also fine tuned the validation method.