beautified code with jsbeautifier.org; fixed some errors