Made code slightly more readable and removed unused functions