code simplified
comments added
warnings fixed