added advice chain handling
cleanup, phpcs and minor bugfixes