Major Revamp to improve code functionality