may have sorted a few bugs in the code