refactored for cleaner obj-c code