Reformatted by phpStorm (https://gist.github.com/Rarst/1370155)