Refactoring and dependencies added.

Also 346e319 and 90339bd fix Issue #50