Complete rewrite to integrate CodeIgniter