Fixed some bugs and made some changes according to drupal coding standards.