Fix warnings and clean code