Fixed Issue #299 and streamlined some code.