Fixed various bugs. Now works on Ubuntu 12.04.