Improve code.

Update code to reduce cyclomatic complexity other mess issues.
Update code to match coding standard issues.
Add ant build script, with phpcs and phpmd checks.