Fix #189, clean code and update documentation