cleanup code
portability changes
reformating for better readability