working solution

all methods work fine.
but. still this code should be written in smarter way