Fixed errors.
added interesting idea from SO