Refactoring cake_query.erl
Corrected refactoring bugs
corrected refactoring bugs of simple_query
Making sure file is always closed after querying
Added alexandre's patch for last_entry_at logic error