Code cleaning + errors catching