Refactoring and cleanup to use external library.