Modified main to improve portability