fixed bug, put everything together