Refactored some logic. Introduced NSValue category.