Added testing procedures, fixed a few bugs