Refactored cake_query.erl