Fixed all bugs, moved many magic numbers to XML file.