Updated code based on comments for issue #1