refactoring (style, performance and security issues)

Hi,

I did some changes and I did spot some "problems" including (but not limited to):

- Possivel SQL injection on a module
- Performance boost using the any? iterator 
- Improving the coding style, rewriting code using a better "ruby dialect" 

I'm open to discussion and improvements ideas. I was able to test my code, partially (I've got some integrations tests, but I've got them as well before my changes). I ran the rake test:api to test it. 

thanks,

VP