big refactoring and additions
refactoring and adding more correctness