Fixes some errors and remove unused code