reordered some code and added strict where missing