fixed issues; refactoring