refactored and formatted
removed warnings
fixed phpdoc