General improvements all over

- Take advantage of bashisms for cleaner and more robust code
- Make variables readonly wherever applicable
- Fix some keychain-related bugs; make it optional
- Show function name in warning/error messages