Edited with Beautify. Also some minor changes