Refactorization to remove redundant code.
Added logging for debugging purposes.
Renamed some functions and updated JavaDoc.
Modified some log messages.