code cleaned up, many warnings fixed