fixes and solution from anonymous