Fix null pointer issue and make it run on desktop

- Eliminated some null-returning methods to fix the NPE.
- Replaced Pair (Android-specific) with custom type to make it run on desktop.