reorganized code

removed useless comments(debugging ones ),
added useful comments
gathered functions by their purpose
removed test() function as it was of no use.
added explaination of messages.