added Peter's code to apk, fixed compilation errors