refactored somejs code to reduce amount of chaining methods used