Removed legacy code
Minor code refractoring
Added comments