fixed Barans code