Some changes according to JSHint, added wrapper function, minor implementation changes