Refactor and commented src code

Hi I like your plugin so I spend this morning refactoring and commenting the code. Keep up the good work!