some minor changes
huge refactoring
made same basic logic