Refactored code and moved old code into iphone controller application