Cleaned code, added phpdoc, standardized indentation

See diff & comments