Refactoring code

Try to make the code a bit better