refactor the implementation to make it more elegant :)