Conversion to Gradle and code cleanup