added phpdoc and refactored factory method