Updated with minor code cleanup.