Code cleanup

- Remove duplicate code
- Utilize korlib where possible