Improved model

1. Simplified SQL a lot.
2. Implemented method "count_messages"
more stable list_messages action
perltidy
do not add the first message..

Do not add the first message to the list of messages
in case we are using offset
satabilized tests