DEV: Remove unused code and fix bugs