Fixed compile and logic errors, behaving now