Cleaned up code and added a global $base_uri variable for the framework to use.