Fix #99 and partially fix #103

Why did you removed lines 403-413 & 425-448 stuff?