Refactored & fixed issues