Convert to Maven

and fixed some bugs.