Fixed some bugs, moved some constants to config file.