moved maintainable parts completely over to PHP