Re-organised source code and improved cmake support