Cleaned code, added phpdoc, standardized indentation