Made code more concise, removed some unnecessary function calls/complexity.