Added api_key_required decorator and some refactoring.