Added error handling for method apply. (better than going panic i think)