fix #12 and code cleanup.