BETA!; Code reformatted (was a mix of indentations due to coding in different OSs)