optimise code and fix naming