Refactor and use lib code style