Refactor listener and split main api into several method for flexibility