Added deep_merge from ActiveSupport.

Also some small fixes, unused variables removing and encapsulation.