Code + build script optimisations

Gradle build removes "dynamic properties" for forward compatibility with
Gradle 2.0.

Code analysis run for optimisations, various small fixes, code style