Fix warnings and clean up code