added new functionality and code cleanup