accounting code simplified and enhanced. more error handling added