Fixed API issue. Refactor code.