Refactoring and cleanup

- Minor updates in error handling.
- Updated string-related functions.
- Work in progress, won't compile.